<template>
  <div>
    <div class="top">
      <el-form :inline="true">
        <el-form-item label="合作商搜索：">
          <el-input v-model="data.name" placeholder="请输入" style="width:180px" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="inquire">
            <i class="el-icon-search" />
            查询</el-button>

        </el-form-item>
      </el-form>
    </div>
    <div class="list">
      <el-button type="warning" @click="xinjian"> <i class="el-icon-circle-plus-outline" /> 新建</el-button>
      <!-- 列表 -->
      <el-table :data="list">
        <el-table-column type="index" label="序号">
          <template scope="scope">
            <span>{{ (data.pageIndex-1)*data.pageSize+scope.$index+1 }}</span>
          </template>
        </el-table-column>

        <el-table-column label="合作商名称">
          <template v-slot="{ row }">
            <span>{{ row ?.name }}</span>
          </template>
        </el-table-column>
        <el-table-column label="账号">
          <template v-slot="{ row }">
            <span>{{ row ?.account }}</span>
          </template>
        </el-table-column>
        <el-table-column label="设备数量">
          <template v-slot="{ row }">
            <span>{{ row ?.vmCount }}</span>
          </template>
        </el-table-column>
        <el-table-column label="分成比例">
          <template v-slot="{ row }">
            <span>{{ row ?.ratio }}%</span>
          </template>
        </el-table-column>
        <el-table-column label="联系人">
          <template v-slot="{ row }">
            <span>{{ row ?.contact }}</span>
          </template>
        </el-table-column>
        <el-table-column label="联系电话">
          <template v-slot="{ row }">
            <span>{{ row ?.mobile }}</span>
          </template>
        </el-table-column>

        <el-table-column width="300px" label="操作">
          <template v-slot="{ row }">
            <el-button type="text" @click="open(row.id)"><span class="xiugai">重置密码</span> </el-button>
            <el-button type="text"><span class="xiugai" @click="poenxiangqing(row)">查看详情</span> </el-button>
            <el-button type="text"><span class="xiugai" @click=" xinjian(row) ">修改</span> </el-button>
            <el-button type="text" style="color: #fb9782;" @click="sahcnhu(row.id)"><span class="shanchu">删除</span> </el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-row type="flex" style="height:60px" align="middle" justify="space-between">
        <span class="record">共{{ totalCount }}条记录 第{{ data.pageIndex }}/ {{ totalPage }} 页</span>
        <el-pagination
          :page-size="data.pagesize"
          :current-page="data.pageIndex"
          layout="prev,  next"
          :total="+totalCount"
          prev-text="上一页"
          next-text="下一页"

          @current-change="changePage"
        />
      </el-row>
    </div>
    <el-dialog
      title="新增合作商"
      :visible.sync="dialogShow"
      width="35%"
      :before-close="handleClose"
    >
      <el-form label-width="80px">
        <el-form-item label-width="120px" label="合作商名称：">
          <el-input v-model="datas.name" placeholder="请输入" maxlength="10" show-word-limit style="width: 450px;" />
        </el-form-item>
        <el-form-item label-width="120px" label="联系人：">
          <el-input v-model="datas.contact" placeholder="请输入" maxlength="10" show-word-limit style="width: 450px; height:50px; " />
        </el-form-item>
        <el-form-item label-width="120px" label="联系电话：">
          <el-input v-model="datas.mobile" placeholder="请输入" maxlength="11" show-word-limit style="width: 450px; height:50px; " />
        </el-form-item>
        <el-form-item label-width="120px" label="分成比例(%)：">
          <el-input-number v-model="datas.ratio" controls-position="right" :min="0" :max="100" style="width: 450px; " />
        </el-form-item>
        <el-form-item v-if="!datas.account" label-width="120px" label="账号：">
          <el-input v-model="datas.account" placeholder="请输入" maxlength="18" show-word-limit style="width: 450px; height:50px; " />
        </el-form-item>
        <el-form-item v-if="!datas.account" label-width="120px" label="密码：">
          <el-input v-model="datas.password" placeholder="请输入" maxlength="20" show-word-limit style="width: 450px; height:50px; " />
        </el-form-item>
        <el-form-item>
          <div class="dialogboxfood">
            <el-button @click="qxpuits">取消</el-button>
            <el-button class="footBtn" type="warning" @click="posttijiao">确定</el-button>
          </div>
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog
      title="合作商详情"
      :visible.sync="dialogShows"
      width="35%"
      :before-close="handleClose"
    >
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form label-width="80px">
            <el-form-item v-if="!datas.account" label-width="120px" label="合作商名称：">
              {{ myRow.name }}
            </el-form-item>
            <el-form-item v-if="!datas.account" label-width="120px" label="联系电话：">
              {{ myRow.mobile }}
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="12"> <el-form label-width="80px">
          <el-form-item v-if="!datas.account" label-width="120px" label="联系人：">
            {{ myRow.contact }}
          </el-form-item>
          <el-form-item v-if="!datas.account" label-width="120px" label="分成比例：">
            {{ myRow.ratio }}%
          </el-form-item>
        </el-form></el-col>
      </el-row>
    </el-dialog>
  </div>
</template>

<script>
import { DELETEhzs, gethezuoshang, POSThezuoshang, PUThezuoshang, PUThzspassword } from '@/api/attendance'
export default {
  name: 'Attendance3',

  data() {
    return {
      dialogShows: false,
      dialogShow: false,
      // 获取列表数据
      data: {
        pageIndex: 1,
        pageSize: 10,
        name: ''
      },
      datass: {
        pageIndex: 1,
        pageSize: 100000,
        regionId: ''
      },
      // 总数据
      totalCount: '',
      // 总页数
      totalPage: '',
      // 列表数据
      list: [],
      // 新增表单
      datas: {
        name: '',
        account: '',
        password: '',
        ratio: '',
        contact: '',
        phone: '',
        mobile: ''
      },
      xiangqLists: [],
      id: null,
      myRow: ''
    }
  },
  created() {
    // 页面列表
    this.getEquipmentList()
  },
  methods: {
    // 关闭弹窗
    handleClose() {
      this.dialogShow = false
      this.dialogShows = false
      this.datas.regionName = ''
      this.datas.remark = ''
      this.id = null
    },
    // 分页
    changePage(newPage) {
      // console.log(newPage)
      this.data.pageIndex = newPage
      // console.log(this.data)
      this.getEquipmentList()
    },
    // 获取列表数据
    async getEquipmentList() {
      console.log(this.data)
      const res = await gethezuoshang(this.data)
      this.list = res.currentPageRecords
      this.totalCount = res.totalCount
      this.totalPage = res.totalPage
      console.log(this.list)
    },
    // 查询重新渲染页面
    inquire() {
      this.getEquipmentList()
    },
    qxpuits() {
      this.dialogShow = false
      this.datas.regionName = ''
      this.datas.remark = ''
      this.id = null
    },
    async posttijiao() {
      if (this.id) {
        const res = await PUThezuoshang(this.datas, this.id)
        console.log(res)
        this.$message.success('修改成功')
      } else {
        await POSThezuoshang(this.datas)
        this.$message.success('新建成功')
      }
      this.getEquipmentList()
      this.datas = {}
      this.id = null
      this.dialogShow = false
    },
    xinjian(row) {
      console.log(row)
      this.id = row.id
      this.datas.name = row.name
      this.datas.account = row.account
      this.datas.password = row.password
      this.datas.ratio = row.ratio
      this.datas.contact = row.contact
      this.datas.phone = row.phone
      this.datas.mobile = row.mobile
      console.log(this.datas)

      this.dialogShow = true
    },
    async poenxiangqing(row) {
      this.myRow = row
      this.dialogShows = true
    },
    async sahcnhu(id) {
      const res = await DELETEhzs(id)
      this.$message.success('删除成功')
      this.getEquipmentList()
      console.log(res)
    },
    async open(id) {
      this.$confirm('', '确定要重置合作商密码吗？', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        const res = PUThzspassword(id)
        console.log(res)
        this.$message({
          type: 'success',
          message: '重置成功!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消重置'
        })
      })
    }

  }
}
</script>

<style  lang='scss' scoped>
.selected{
position: relative;
    width: 134px;
    height: 134px;
    padding-top: 16px;
    background-color: #f6f7fb;
    -webkit-box-shadow: 0 2px 4px 0 rgba(0,0,0,.06);
    box-shadow: 0 2px 4px 0 rgba(0,0,0,.06);
    border-radius: 4px;
    text-align: center;
    cursor: pointer;
}
 .top{
    height: 80px;
    margin: 20px;
    padding: 18px;
    background-color: #fff;
  }
    .list{
    padding: 18px;
    margin: 20px;
    background-color: #fff;
   }
    ::v-deep.el-pagination .btn-next{
  background-color: #d5ddf8 !important;
  width: 70px;
  height: 30px;
  text-align: center;
  border-radius: 3px;
   margin: 10px;
}

::v-deep.el-pagination .btn-prev{
  background-color: #d5ddf8 !important;
  width: 70px;
  height: 30px;
  text-align: center;
  border-radius: 3px;
  margin: 10px;
}
.record{
  color: #dbdfe5;
}
.xiugai{
  color: #6eabfe;
}
.sahnchu{
  color: #fb9782;
}
.rowimg{
      display: block;
    width: 24px;
    height: 24px;
    -o-object-fit: cover;
    object-fit: cover;
    border-radius: 50%;
    background: #f3f6fb;
    border: 1px solid #f3f6fb;
}
  .avatar-uploader .el-upload {
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    border: 2px dashed  #b7b7b7 !important;
    font-size: 28px;
    color: #8c939d;
    background-color: #f3f6fb;
    width: 100px;
    height:100px;
    line-height: 100px;
    text-align: center;
  }
  .avatar {
    // border: 2px dashed  #000 !important;
    width: 100px;
    height:100px;
    display: block;
  }
  .dialogboxfood{
    width: 70%;
    display: flex;
    justify-content: center;
    .footBtn{
      margin-left: 60px;
    }
  }
.rowimg{
      display: block;
    width: 24px;
    height: 24px;
    -o-object-fit: cover;
    object-fit: cover;
    border-radius: 50%;
    background: #f3f6fb;
    border: 1px solid #f3f6fb;
}
</style>
